<?php

$url = 'http://www.bash.org.ru/best';
$widget_topic     = isset($widget_topic)     ? $widget_topic     : 'day';
$widget_msg_count = isset($widget_msg_count) ? $widget_msg_count : 5;



$html = NULL;
if (ini_get('allow_url_fopen')) {
	$html = file_get_contents($url);
} elseif (function_exists('curl_init')) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_TIMEOUT, 5);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
	$html = curl_exec($ch);
	curl_close($ch);
}

if (isset($html)) {
	$html = iconv('cp1251', 'utf-8', $html);

	$topics['day'] = 1;
	$topics['week'] = 2;
	$topics['month'] = 3;

	$atopics = split('<h2>',$html);

	preg_match_all('|<div>(.+)</div>|U', $atopics[$topics[$widget_topic]], $frazes);

	if ($widget_msg_count > 5) $widget_msg_count++;

	for($i=0; $i<$widget_msg_count; $i++){
		if ($i<>5) echo "<hr>".$frazes[1][$i]."</hr>\n";
	}
} else {
	echo 'Server unavailable';
}

